package com.woniu.controller;


import cn.hutool.core.bean.BeanUtil;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.commons.exception.YogaException;
import com.woniu.commons.model.Result;
import com.woniu.model.dto.CoachTypeDto;
import com.woniu.model.entity.YCoachType;
import com.woniu.model.entity.YUser;
import com.woniu.model.form.AddCoachTypeForm;
import com.woniu.model.form.PageCoachTypeForm;
import com.woniu.model.form.PageForm;
import com.woniu.model.form.changeCoachTypeForm;
import com.woniu.model.param.AddCoachTypeParam;
import com.woniu.model.param.PageCoachTypeParam;
import com.woniu.model.param.PageParam;
import com.woniu.model.param.changeCoachTypeParam;
import com.woniu.service.YCoachTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 胡歌
 * @since 2024年05月22日
 */
@RestController
@RequestMapping("/yCoachType")
@Api(tags = "教练类型的一些接口")
public class YCoachTypeController {
    @Resource
    private YCoachTypeService coachTypeService;

    /**
     * 新增教练类型
     * @param form
     * @return
     * @throws Exception
     */
    @PostMapping("/addCoachType")
    @ApiOperation("新增教练类型")
    @Transactional
    public Result addCoachType(@RequestBody AddCoachTypeForm form)throws Exception{
        coachTypeService.addCoachType(BeanUtil.toBean(form, AddCoachTypeParam.class));
        return Result.getResult().setMsg("新增教练类型成功");
    }

    /**
     * 禁用教练类型
     * @param
     * @return
     * @throws Exception
     */

    @GetMapping("/disable")
    @ApiOperation("禁用教练类型")
    public Result disable(Integer coachTypeId){
        coachTypeService.disable(coachTypeId);
        return Result.getResult().setMsg("禁用教练类型成功");
    }

    /**
     * 启用教练类型
     * @param
     * @return
     * @throws Exception
     */

    @GetMapping("/enable")
    @ApiOperation("启用教练类型")
    public Result enable(Integer coachTypeId){
        coachTypeService.enable(coachTypeId);
        return Result.getResult().setMsg("启用教练类型成功");
    }


    /**
     * 根据id查找教练类别信息
     * @param id
     * @return
     */
    @GetMapping("/byId/{id}")
    @ApiOperation("根据id查找教练类别信息")
    public Result<CoachTypeDto> byId(@PathVariable("id") Integer id){
        YCoachType coachType = coachTypeService.getById(id);
        return Result.newInstance(CoachTypeDto.class).setData(BeanUtil.toBean(coachType,CoachTypeDto.class));
    }


    /**
     * 修改教练类别
     * @param form
     * @return
     */
    @PostMapping("/changeCoachType")
    @ApiOperation("修改教练类别")
    public Result changeCoachType(@RequestBody changeCoachTypeForm form){
        changeCoachTypeParam param=BeanUtil.toBean(form, changeCoachTypeParam.class);
        coachTypeService.updateById(BeanUtil.toBean(param,YCoachType.class));
        return Result.getResult().setMsg("修改教练类别成功");
    }

    /**
     * 根据ID删除教练类别
     * @param classTypeId
     * @return
     */
    @GetMapping("/deleteById")
    @ApiOperation("根据ID删除教练类别")
    public Result deleteById( Integer classTypeId){
        coachTypeService.classTypeId(classTypeId);
        return Result.getResult().setMsg("根据ID删除教练类别成功").setCode(200);
    }

    /**
     * 展示所有教练类别
     * @return
     */

    @GetMapping("/seatInfoList")
    @ApiOperation("展示所有教练类别")
    public Result<List<CoachTypeDto>> seatInfoList(){
        List<CoachTypeDto> dtos = coachTypeService.seatInfoList();
        return Result.newListInstance(CoachTypeDto.class).setData(dtos).setCode(200);
    }

    /**
     * 分页查询所有类型
     * @param form
     * @return
     * @throws Exception
     */
    @GetMapping("/pageAllCoachType")
    @ApiOperation("分页查询所有类型")
    public Result<Page<YCoachType>> pageAllCoachType(PageCoachTypeForm form) throws YogaException {
        Page<YCoachType> page = coachTypeService.pageAllCoachType(BeanUtil.toBean(form, PageCoachTypeParam.class));
        return Result.newPageInstance(YCoachType.class).setMsg("查询成功").setData(page).setCode(200);
    }




}

